﻿Imports System.Runtime.InteropServices

Class IconFactory
    Private Structure SHFILEINFO
        Public hIcon As IntPtr            ' : icon
        Public iIcon As Integer           ' : icondex
        Public dwAttributes As Integer    ' : SFGAO_ flags
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Public szDisplayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szTypeName As String
    End Structure

    Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
        (ByVal pszPath As String, _
         ByVal dwFileAttributes As Integer, _
         ByRef psfi As SHFILEINFO, _
         ByVal cbFileInfo As Integer, _
         ByVal uFlags As Integer) As IntPtr
    Private Const SHGFI_ICON = &H100
    Private Const SHGFI_SMALLICON = &H1
    Private Const SHGFI_LARGEICON = &H0    ' Large icon
    Private nIndex = 0

    Shared Function GetIcon(ByVal fName As String) As System.Drawing.Icon
        Dim hImgSmall As IntPtr  'The handle to the system image list. 

        Dim shinfo As SHFILEINFO
        shinfo = New SHFILEINFO()


        shinfo.szDisplayName = New String(Chr(0), 260)
        shinfo.szTypeName = New String(Chr(0), 80)




        'Use this to get the small icon.
        hImgSmall = SHGetFileInfo(fName, 0, shinfo, _
                    Marshal.SizeOf(shinfo), _
                    SHGFI_ICON Or SHGFI_SMALLICON)

        'Use this to get the large icon.
        'hImgLarge = SHGetFileInfo(fName, 0,
        'ref shinfo, (uint)Marshal.SizeOf(shinfo),
        'SHGFI_ICON | SHGFI_LARGEICON);
        'The icon is returned in the hIcon member of the
        'shinfo struct.
        Dim myIcon As System.Drawing.Icon
        myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)

        Return myIcon

    End Function

End Class

Module ModuleImports

 


    ''' <summary>
    ''' A hard link is a way to represent a single file (i.e. data volume) by more than one path. In other words, 
    ''' it is a way to create multiple directory entries for a single file. 
    ''' </summary>
    ''' <param name="lpFileName"></param>
    ''' <param name="lpExistingFileName"></param>
    ''' <param name="lpSecurityAttributes"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
    Function CreateHardLink(ByVal lpFileName As String, ByVal lpExistingFileName As String, ByVal lpSecurityAttributes As IntPtr) As Boolean
    End Function


    ''' <summary>
    ''' Soft links (also called junctions,) are identical to hard links 
    ''' except that soft links are designated for directories not files. 
    ''' </summary>
    ''' <param name="lpSymlinkFileName"></param>
    ''' <param name="lpTargetFileName"></param>
    ''' <param name="dwFlags"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
    Function CreateSymbolicLink(ByVal lpSymlinkFileName As String, ByVal lpTargetFileName As String, ByVal dwFlags As SYMBOLIC_LINK_FLAG) As Boolean

    End Function

    Enum SYMBOLIC_LINK_FLAG As Integer
        File = 0
        Directory = 1
    End Enum
End Module
